package com.my.controller;


import com.my.bean.*;
import com.my.service.KitchenArrangeService;
import com.my.util.SessionUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 厨房每日工作安排 前端控制器
 * </p>
 *
 * @author 闫亚茹
 * @since 2018-08-28
 */
@Controller
@RequestMapping("/kitchenArrange")
public class KitchenArrangeController {
    @Autowired
    KitchenArrangeService kitchenArrangeService;
    Logger logger=Logger.getLogger(WorkguidaceController.class);

    /**
     * 添加
     * @param kitchenArrange
     * @return
     */
    @RequestMapping("/addbakitchenArrange")
    @ResponseBody
    public  String addbakitchenArrange(KitchenArrange kitchenArrange) {
        if (kitchenArrangeService.insert(kitchenArrange)) {
            logger.info("{addbakitchenArrange|保存成功}");
            return "添加成功";
        } else {
            logger.info("{addbakitchenArrange|添加失败}");
            return "添加失败";
        }

    }


    /**
     * 查询所有数据并分页
     * @param voPage
     * @return
     */
    @RequestMapping("/selectKitchen")
    @ResponseBody
    public ResultPage<KitchenArrange> selectKitchen(VoPage voPage, HttpSession session){
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        ResultPage<KitchenArrange> resultPage = kitchenArrangeService.selectMyPage(voPage);
        return  resultPage;
    }
    @RequestMapping("/kitchen")
    public String kitchen(){
        return "kitchen";
    }


    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping("/deleteKitchenArrange")
    @ResponseBody
    public boolean deleteKitchenArrange(Long id){
        return kitchenArrangeService.deleteById(id);
    }

    /**
     * 修改
     */
    @RequestMapping("/updateKitchenArrange")
    @ResponseBody
    public String updateKitchenArrange(KitchenArrange kitchenArrange){
        List<KitchenArrange> list = new ArrayList<>();
        list.add(kitchenArrange);
        if(kitchenArrangeService.updateBatchById(list)){
            return "修改成功";
        }else{
            return "修改失败";
        }
    }


}
